package gui.entity;

import generated.domain.world.World;

import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;

public class WorldElementPropertySource implements IPropertySource {

	private static final String PROPERTY_ID_NAME = "world.name";
	private static final Object PROPERTY_ID_SIZE = "world.size";
	private final World world;

	private IPropertyDescriptor[] propertyDescriptors;

	public WorldElementPropertySource(WorldEntity element) {
		world = element.getWorld();
	}

	public IPropertyDescriptor[] getPropertyDescriptors() {
		if (propertyDescriptors == null) {
			PropertyDescriptor nameDescriptor = new PropertyDescriptor(
					PROPERTY_ID_NAME, "Name");

			PropertyDescriptor sizeDescriptor = new PropertyDescriptor(
					PROPERTY_ID_SIZE, "Size");

			propertyDescriptors = new IPropertyDescriptor[] { nameDescriptor,
					sizeDescriptor };
		}
		return propertyDescriptors;
	}

	public Object getEditableValue() {
		return null;
	}

	public Object getPropertyValue(Object id) {
		if (id.equals(PROPERTY_ID_NAME))
			return world.name;
		if (id.equals(PROPERTY_ID_SIZE))
			return "[" + world.size.rowNumber + "," + world.size.columnNumber
					+ "]";
		return "";
	}

	public boolean isPropertySet(Object id) {
		return false;
	}

	public void resetPropertyValue(Object id) {
	}

	public void setPropertyValue(Object id, Object value) {
	}
}